program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
type
  arr=array of integer;
var
  fin, fout: textfile;
  n, i, j, a, b, colour, flag1, flag2, count, x, k, l: integer;
  col: array of integer;
  mass: array of arr;
begin
  assignfile(fin, 'input.txt');
  reset(fin);
  assignfile(fout, 'output.txt');
  rewrite(fout);
  readln(fin, n);
  flag1:=0;
  flag2:=0;
  count:=n;
  setlength(col, n);
  setlength(mass, n);
  for i:=0 to n-1 do
    setlength(mass[i], n);           
  for i:=0 to n-1 do
    col[i]:=i;
  for i:=0 to n-1 do
    for j:=0 to n-1 do
      read(fin, mass[i, j]);
  x:=0;
  for i:=0 to n-1 do
    for j:=0 to n-1 do
      if (mass[i, j]<>0) then
        x:=x+1;
  x:=x div 2;
  if (x+1=n) then
    flag2:=1;
  for i:=0 to n-1 do
  begin
    for j:=0 to n-1 do
    begin
      if (col[i]<>col[j]) and (mass[i, j]<>0) then
      begin
        count:=count-1;
        colour:=col[i];
        for k:=0 to n-1 do
          if (col[k]=colour) then
            col[k]:=col[j];
        mass[i, j]:=0;
        mass[j, i]:=0;
      end;
    end;
  end;
  if (count=1) then
    flag1:=1;
  if (flag1=1) and (flag2=1) then
  begin
    writeln(fout, 'YES');
  end else begin
    writeln(fout, 'NO');
  end;
  closefile(fin);
  closefile(fout);
end.
 